package com.jsnu.xiaochi.service;

import com.jsnu.xiaochi.dao.CategoryMapper;
import com.jsnu.xiaochi.dao.FoodMapper;
import com.jsnu.xiaochi.pojo.Category;
import com.jsnu.xiaochi.pojo.CategoryExample;
import com.jsnu.xiaochi.pojo.Food;
import com.jsnu.xiaochi.pojo.FoodExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AdminServiceImpl implements AdminService {
    @Resource
    FoodMapper foodMapper;
    @Resource
    CategoryMapper categoryMapper;

    @Override
    public List<Food> getNoPassFood() {
        FoodExample foodExample = new FoodExample();
        foodExample.createCriteria().andStatusEqualTo("0");
        return foodMapper.selectByExample(foodExample);
    }

    @Override
    public List<Food> getPassFood() {
        FoodExample foodExample = new FoodExample();
        foodExample.createCriteria().andStatusEqualTo("1");
        return foodMapper.selectByExample(foodExample);
    }

    @Override
    public int goPass(String id) {
        Food food=new Food();
        food.setId(id);
        food.setStatus("1");
        return foodMapper.updateByPrimaryKeySelective(food);
    }

    @Override
    public List<Category> getAllCategory() {
        CategoryExample categoryExample = new CategoryExample();
        return categoryMapper.selectByExample(categoryExample);
    }

    @Override
    public int deleteCategory(int id) {
        return categoryMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int editCategory(Category category) {
        return categoryMapper.updateByPrimaryKey(category);
    }

    @Override
    public int insertCategory(Category category) {
        return categoryMapper.insert(category);
    }

    @Override
    public int updateFood(Food food) {
        return foodMapper.updateByPrimaryKeySelective(food);
    }

    @Override
    public int deleteFood(String id) {
        return foodMapper.deleteByPrimaryKey(id);
    }
}
